package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username     string `json:"username" gorm:"uniqueIndex;size:50;not null"`
	PasswordHash string `json:"-" gorm:"size:255;not null"`
}

type Post struct {
	gorm.Model
	UserID        uint   `json:"user_id" gorm:"not null;index"`
	Title         string `json:"title" gorm:"size:255;not null"`
	Content       string `json:"content" gorm:"type:text;not null"`
	VoteCount     int    `json:"vote_count" gorm:"default:0;index"`
	UpvoteCount   int    `json:"upvote_count" gorm:"default:0"`
	DownvoteCount int    `json:"downvote_count" gorm:"default:0"`
	CommentCount  int    `json:"comment_count" gorm:"default:0"`
	ViewCount     int    `json:"view_count" gorm:"default:0"`
}

// Vote 投票模型
type Vote struct {
	gorm.Model
	UserID   uint `json:"user_id" gorm:"not null;index"`
	PostID   uint `json:"post_id" gorm:"not null;index"`
	VoteType int  `json:"vote_type" gorm:"not null;comment:投票类型 1-赞成 -1-反对"`

	// 关联关系
	User *User `json:"user,omitempty" gorm:"foreignKey:UserID"`
	Post *Post `json:"post,omitempty" gorm:"foreignKey:PostID"`
}

const (
	VoteTypeDown = -1
	VoteTypeUp   = 1
)
